<template>
  <div>
    <el-form ref="myform" :model="formItem" label-width="100px" size="mini" class="form-view">
      <el-row :gutter="40">
        <el-col :span="12">
          <el-form-item label="参与工程师">
            {{ formItem.helperEngineerName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="故障级别">
            {{ getfailureLevelName(formItem.faultLevel) }}
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="组长审批意见">
            <div class="height-div">
              {{ formItem.approvalComments }}
            </div>
          </el-form-item>
        </el-col>
        <el-col v-if="formItem.secondOperatorName" :span="24">
          <el-form-item label="二线组长">
            {{ formItem.secondOperatorName }}
          </el-form-item>
        </el-col>
        <el-col v-if="formItem.transferSecondlineReason" :span="24">
          <el-form-item label="转派原因">
            <div class="height-div">
              {{ formItem.transferSecondlineReason }}
            </div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { leaderApprovalDetail as detail } from '@neu/dcom-ui/api/malfunction'
import { findByDictionaryType } from '@neu/dcom-ui/api/dictionary'

const formItem = {
  // 工作流TaskId
  taskId: '',
  // 工单号
  workNum: '',
  // 审批意见
  approvalComments: '',
  // 操作人编码
  operatorCode: '',
  // 操作人姓名
  operatorName: '',
  // 是否同意
  whetherAgree: false,
  // 是否转二线
  whetherTransfer: false,
  // 二线操作人编码
  secondOperatorCode: '',
  // 二线操作人编码名称
  secondOperatorName: '',
  // 参与一线工程师编码
  helperEngineerCode: '',
  // 参与一线工程师名称
  helperEngineerName: '',
  // 转二线原因
  transferSecondlineReason: ''
}

export default {
  name: 'LeaderApprovalViewForm',
  props: {
    taskId: {
      required: false,
      type: String,
      default: 'NULL'
    },
    workOrderNum: {
      required: false,
      type: String,
      default: ''
    }
  },
  data() {
    return {
      // 所有的故障级别
      availableFailureLevels: [],
      formItem: {
        ...formItem
      }
    }
  },
  created() {
    // 故障级别
    findByDictionaryType('failureLevel').then(response => {
      this.availableFailureLevels = response.data
    })
    this.fetch()
  },
  methods: {
    fetch() {
      if (this.workOrderNum !== 'NULL') {
        detail(this.workOrderNum, this.taskId).then(response => {
          this.formItem = {
            ...response.data
          }
        })
      } else {
        this.formItem = {
          ...formItem
        }
      }
    },
    getfailureLevelName(code) {
      const one = this.availableFailureLevels.find(e => e.code === code)
      return one ? one.text : ''
    }
  }
}
</script>

<style lang="scss" scoped>
.height-div {
    min-height: 80px;
    max-height: 100px;
}
</style>
